package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CategoryController {
	@Autowired
	private CategoryService categoryService;
	@GetMapping("/category/findAll")//category/findAll
	public ResultInfo finAll(){
		
		return ResultInfo.success(categoryService.findAll());
	}
	
	@PostMapping("/category")
	public ResultInfo save(@RequestBody Category category) {
		categoryService.save(category);
		return ResultInfo.success("ok");
	}
	
	@PutMapping("/category")
	public ResultInfo update(@RequestBody Category category) {
		categoryService.update(category);
		return ResultInfo.success("ok");
	}
	
	@DeleteMapping("/category")
	// @RequestMapping(path = "/category/{id}",method = RequestMethod.DELETE)
	public ResultInfo delete(String id){
		categoryService.deleteById(id);
		return ResultInfo.success("ok");
	}
	//根据类型查询分类列表
	@GetMapping("/category/list")
	public ResultInfo findByType(Integer type){
		
		return ResultInfo.success(categoryService.findByType(type));
	}
}
